﻿using System;
using System.Linq;
using System.Web.Mvc;
using BLL;
using Model;


namespace Web.Areas.Manager.Controllers
{
    [UserAuthorize]
    public class TimeCardController : Controller
    {
        TimeCard_BLL _TimeCard_BLL = new TimeCard_BLL();
        TimeCardSet_BLL _TimeCardSet_BLL = new TimeCardSet_BLL();

        public virtual ActionResult Index(int? pageIndex, string keyword, DateTime? date)
        {

            ViewBag.timecardset = _TimeCardSet_BLL.Get();

            if (date == null)
            {
                date = DateTime.Now;
            }

            ViewBag.Year = date.Value.Year;
            ViewBag.Month = date.Value.Month;

            var model = _TimeCard_BLL.Get().Where(a => a.Sys_Users.Id.Equals(new Guid(User.Identity.Name)) && a.AddDate.Year == date.Value.Year && a.AddDate.Month == date.Value.Month);
            return View(model);
        }


        public virtual ActionResult Details(Guid Id)
        {
            var item = _TimeCard_BLL.Get(Id);
            return View(item);
        }

        public virtual ActionResult Edit(Guid? Id)
        {
            var item = _TimeCard_BLL.Get(Id);
            return View(item);
        }

        [HttpPost]
        public virtual ActionResult Edit(Guid? Id, TimeCard collection)
        {
            if (!ModelState.IsValid)
            {
                return View(collection);
            }
            _TimeCard_BLL.Save(Id, ref collection);
            return RedirectToAction("Index", RouteData.Values);
        }

        [HttpDelete]
        public virtual ActionResult Delete(Guid Id)
        {
            _TimeCard_BLL.Delete(Id);
            return RedirectToAction("Index", RouteData.Values);
        }
    }
}
